package process

import (
	"chat/common/msg"
	"chat/utils"
	"encoding/json"
	"fmt"
)

type SmsProcess struct {
}

// 发送群聊消息
func (this *SmsProcess) SendGroupMes(content string) (err error) {
	//创建 msg
	var mes msg.Message
	mes.Type = msg.SmsMesType

	var smsMes msg.SmsMes
	smsMes.Content = content
	smsMes.UserId = CurrUser.UserId
	smsMes.Username = CurrUser.Username
	smsMes.UserStatus = CurrUser.UserStatus

	data, err := json.Marshal(smsMes)
	if err != nil {
		fmt.Println("SendGroupMes smsMes Marshal error = ", err)
		return
	}
	mes.Data = string(data)
	data, err = json.Marshal(mes)
	if err != nil {
		fmt.Println("SendGroupMes mes Marshal error = ", err)
		return
	}

	tf := &utils.Transfer{
		Conn: CurrUser.Conn,
	}
	err = tf.WritePkg(data)
	if err != nil {
		fmt.Println("SendGroupMes WritePkg error = ", err)
		return
	}
	return
}
